home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1990: Discy Business / Discy Business.2mg / DEV.CD / TOOLS / TECH.NOTES / IIGS / TN.IIGS.003 < prev    next >
Encoding:
Text File  |  1988-12-04  |  16.6 KB  |  427 lines  |  [04] ASCII Text (0x0000)

  1. Apple II
  2. Technical Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6.  
  7. Apple IIGS
  8. #3:    Window Information Bar Use
  9.  
  10. Revised by:    Dan Oliver                                       November 1988
  11. Written by:    Dan Oliver                                        October 1986
  12.  
  13. This Technical Note details the use of a window's information bar, including a 
  14. code sample which places a menu in an information bar.
  15. _____________________________________________________________________________
  16.  
  17. Apple IIGS window information bars are not as straightforward as other window 
  18. features, and one reason for this is the small amount of space originally 
  19. allocated for their processing.  If you feel your application can benefit from 
  20. the use of information bars, you can implement them, and this Technical Note 
  21. explains how to do it and includes some suggestions for their use.  The code 
  22. samples below demonstrate how to place a menu bar in an information bar, but  
  23. your use of information bars is not limited to those described here.
  24.  
  25.  
  26. Information Bar Initialization
  27.  
  28. You can create an information bar in a window when you create the window by 
  29. setting the following fields in the parameter list you pass to NewWindow:
  30.  
  31. wFrame          Set bit 4.
  32.  
  33. wInfoHeight     Set to the height of the information bar (should not exceed 
  34.                 window height).
  35.  
  36. wInfoDefProc    Set to the address of the information bar definition 
  37.                 procedure (see below).
  38.  
  39. If you create a window as visible, the Window Manager will call your 
  40. information bar definition procedure (InfoDefProc) before returning from 
  41. NewWindow.  If you have to create the contents of the information bar after 
  42. the window, you will have a problem since the Window Manager will expect your 
  43. InfoDefProc to draw things which do not yet exist.  You can solve this problem 
  44. by creating the window as invisible, creating the contents of the information 
  45. bar, then showing the window.  Another solution would be to detect, in the 
  46. InfoDefProc, that the contents of the information bar do not yet exist.
  47.  
  48. Below is an example of initializing a window's information bar to contain a 
  49. menu bar.  The three key fields of the parameter list which you pass to 
  50. NewWindow are as follows:
  51.  
  52. wFrame          Set bit 4 = 1 and bit 5 = 0 for an invisible window; the 
  53.                 other bits do not affect the information bar, so you can set 
  54.                 them as you wish.
  55.  
  56. wInfoHeight     Assuming you are using a system menu bar and initializing it 
  57.                 before the window, set to the height FixMenuBar returned 
  58.                 when you created the system menu bar.  If you would rather 
  59.                 use an absolute value, which we do not advise, you could use 
  60.                 14 which should be about right for the current system font.
  61.  
  62. wInfoDefProc    Set to the address of the InfoDefProc, in this case 
  63.                 draw_info.
  64.  
  65. After you create the window, but before you show it, you can create the menu 
  66. bar to place in the information bar.  The code to create the menu bar might 
  67. look like the following:
  68.  
  69. window        Direct page location that contains pointer to window's port.
  70. ;
  71. ; --- Create a menu bar --------------------------------------------------------------------
  72. ;
  73.         pha                             Space for result.
  74.         pha
  75.         pea    $FFFF                    Set "use current port" flag.
  76.         pea    $FFFF
  77.         _NewMenuBar                     Create a menu bar.
  78.         pla                             Get returned menu bar handle.
  79.         sta    <menuBar                 Remember menu bar handle.
  80.         pla
  81.         sta    <menuBar+2
  82. ;    
  83. ;
  84. ; --- Store menu bar's handle in the window's InfoRefCon -----------------------------------
  85. ;
  86.         pei    <menuBar+2               Pass menu bar handle.
  87.         pei    <menuBar
  88.         pei    <window+2                Window to set refCon.
  89.         pei    <window
  90.         _SetInfoRefCon                  Store menu bar handle in window's infoRefCon.
  91. ;
  92. ;
  93. ; --- Make the window's menu bar the current menu bar --------------------------------------
  94. ;
  95.         pei    <menuBar+2               Pass menu bar handle.
  96.         pei    <menuBar
  97.         _SetMenuBar                     Make new menu bar the current menu bar.
  98.  
  99. ;
  100. ;
  101. ; --- Get the RECT of the window's information bar -----------------------------------------
  102. ;
  103.         pea    tempRect|-16             Pass pointer of RECT.
  104.         pea    tempRect
  105.         pei    <window+2                Pass pointer of window.
  106.         pei    <window
  107.         _GetRectInfo                    tempRect = interior RECT of window's Info Bar.
  108.  
  109.  
  110. ; --- Dereference menu bar handle ----------------------------------------------------------
  111. ;
  112.         ldy    #2    
  113.         lda    [menuBar],y
  114.         tay
  115.         lda    [menuBar]
  116.         sta    <menuBar                 Now menuBar is the pointer to the Menu Bar.
  117.         sty    <menuBar+2
  118. ;
  119. ;
  120. ; --- Set size of menu bar -----------------------------------------------------------------
  121. ;
  122. ;
  123.         lda    <tempRect+y1
  124.         dec    a                        Overlap top side.
  125.         ldy    #CtlRect+y1    
  126.         sta    [menuBar],y
  127. ;
  128.         lda    <tempRect+x1
  129.         dec    a                        Overlap left side.
  130.         ldy    #CtlRect+x1    
  131.         sta    [menuBar],y
  132. ;
  133.         lda    <rect+y2
  134.         inc    a                        Overlap bottom side.
  135.         ldy    #CtlRect+y2
  136.         sta    [menuBar],y
  137. ;
  138. ;
  139. ; --- Set flag to tell Menu Manager to draw menu in current port ---------------------------
  140. ;
  141.         ldy    #CtlOwner+2              Set high bit in CtlOwner.
  142.         lda    [menuBar],y
  143.         ora    #$8000
  144.         sta    [menuBar],y
  145. ;
  146. ;
  147. ; --- Create the menus and add them to the window's menu bar -------------------------------
  148. ;
  149.         lda    #4
  150. loop    pha                             Save index into menu list.
  151.         tay                             Switch index to Y.
  152. ;
  153.         pha                             Space for return value.
  154.         pha
  155.         lda    menu_list+2,y            Pass address of menu/item lines.
  156.         pha
  157.         lda    menu_list,y
  158.         pha
  159.         _NewMenu
  160. ;                                       Menu handle already on stack.
  161.         pea    0                        Insert menu list at front of list.
  162.         _InsertMenu                     Add my menus to the system menu bar.
  163. ;
  164.         pla
  165.         sec
  166.         sbc    #4
  167.         bpl    loop
  168. ;
  169. ;
  170. ; --- Initialize the size of the menu bar and menus ----------------------------------------
  171. ;
  172.         pha                             Space for returned bar height.
  173.         _FixMenuBar                     Fix up positions in the menu bar.
  174.         pla                             Discard height of menu bar.
  175. ;
  176. ;
  177. ; --- Restore the system menu bar as the current menu --------------------------------------
  178. ;
  179.         pea    0                        Pass flag for system menu bar.
  180.         pea    0
  181.         _SetMenuBar                     Make system menu bar current.
  182.  
  183. The window's menu bar is now initialized, and you can make the window visible 
  184. with a call to ShowWindow; the InfoDefProc will draw the menu bar.
  185.  
  186.  
  187. Information Bar Definition Procedure (InfoDefProc)
  188.  
  189. The InfoDefProc is slightly misleading; it is only responsible for drawing the 
  190. interior, above the background, of the information bar.  The InfoDefProc is 
  191. not responsible for defining the information bar, drawing the frame and 
  192. background, testing for hits, or tracking the user.  The InfoDefProc is 
  193. located inside your application, and the Window Manager calls it whenever it 
  194. needs to draw the part of the window frame that contains the information bar.  
  195. Each window with an information bar can have its own InfoDefProc, or they can 
  196. call share a common InfoDefProc.  When the Window Manager calls your 
  197. InfoDefProc, it sets the proper port, the Window Manager's port, and the 
  198. proper state, an origin local to the window frame and clipped to any windows 
  199. above.  The direct page and data bank are not defined and should be considered 
  200. unknown.
  201.  
  202. The Window Manager passes your InfoDefProc the following information:
  203.  
  204. o    Pointer to the information bar's interior rectangle (less frame), local 
  205.      coordinates.
  206. o    Value of the window's wInfoRefCon, set and used only by your application.
  207. o    Pointer to the window's port (do not switch to this port for drawing).
  208.  
  209. A window that has an information bar containing a menu bar (handle stored in 
  210. the window's InfoRefCon) might have a InfoDefProc as follows:
  211.  
  212. draw_info    START
  213. ;
  214. theWindow    equ    6                   Offset to the information bar owner window.
  215. infoRefCon   equ    theWindow+4         Offset to the window's information bar RefCon.
  216. infoRect     equ    infoRefCon+4        Offset to the information bar's enclosing RECT.
  217. ;
  218.         phd                             Save original direct page.
  219.         tsc                             Switch to direct page in stack.
  220.         tcd
  221. ;
  222. ;
  223. ; --- Draw the window's menu bar in the window's information bar ---------------------------
  224. ;
  225.         pei    infoRefCon+2             Pass handle of window's menu bar handle.
  226.         pei    infoRefCon
  227.         _SetMenuBar                     Make the window's menu bar the current menu bar.
  228. ;
  229.         _DrawMenuBar                    Draw the window's menu bar, as requested.
  230. ;
  231.         lda    #0                       Zero is the flag for the system menu bar.
  232.         pha
  233.         pha
  234.         _SetMenuBar                     Make the system menu bar current again.
  235. ;
  236. ;
  237. ; --- Remove input parameters from the stack -----------------------------------------------
  238. ;       ldx    #12        
  239.         ply                             Pull original direct page off stack, save in Y.
  240. ;
  241.         tsc                             Move direct page point to stack.
  242.         tcd  
  243.         lda    2,s                      Move return address down over input parameters.
  244.         sta    2,x
  245.         lda    0,s
  246.         sta    0,x
  247. ;
  248.         tsc                             Adjust stack for stripped input parameters.
  249.         phx                             Number of bytes of input parameters.
  250.         clc
  251.         adc    1,s                      Add number of input parameters to stack pointer.
  252.         tcs                             And reset stack.
  253. ;
  254.         tya                             Restore original direct page.
  255.         tcd
  256. ;
  257.         rtl                             Return to Window Manager.
  258.         END
  259.  
  260.  
  261. Information Bar Environment
  262.  
  263. An information bar is part of a window's frame, that is, not part of the 
  264. window's content region.  Because it is part of the frame, an information bar 
  265. is in the Window Manager's port, so before an interaction (drawing or mouse 
  266. selecting), the proper port (Window Manager's) must be in the proper state.  
  267. The proper state means the origin must be at the window's upper-left corner 
  268. and clipped to any windows above.
  269.  
  270. When the Window Manager calls the InfoDefProc it sets the proper port to the 
  271. proper state; however, to interact with the information bar outside the 
  272. InfoDefProc, you must set the proper port the the proper state.  You can 
  273. accomplish this with a call to StartInfoDrawing.  When the interaction is 
  274. completed, you must allow the Window Manager to return its port to a general 
  275. state via a call to EndInfoDrawing.  You are in a special state that requires 
  276. some constraints (discussed later) between the calls to StartInfoDrawing and 
  277. EndInfoDrawing.
  278.  
  279. Here is an example of interacting with our window's menu bar.
  280.  
  281. ;
  282. poll    pha                             Space for return value.
  283.         pea    %0000111101101110        Pass event mask to use.
  284.         pea    TaskRec|-16              Pass pointer to Task record.
  285.         pea    TaskRec
  286.         _TaskMaster
  287.         pla                             Get returned value.
  288.         beq    poll                     Does event need further processing?
  289. ;
  290. ;
  291. ; --- Handle button down in window's information bar ---------------------------------------
  292. ;
  293.         cmp    #InInfo                  In Information bar?
  294.         bne    poll
  295. ;
  296.         pha                             Space for result.
  297.         pha
  298.         lda    TaskRec+TaskData+2       Pass pointer of window.
  299.         pha
  300.         lda    TaskRec+TaskData
  301.         pha
  302.         _GetInfoRefCon                  Get menu bar handle from window's InfoRefCon.
  303.         pla
  304.         sta    menuBar
  305.         pla
  306.         sta    menuBar+2
  307. ;            
  308. ;
  309. ; --- Switch to proper port in proper coordinate system ------------------------------------
  310. ;
  311.         pea    tempRect|-16             Pass pointer to RECT to store info bar RECT.
  312.         pea    tempRect
  313.         lda    TaskRec+TaskData+2       Pass pointer of window.
  314.         pha
  315.         lda    TaskRec+TaskData
  316.         pha
  317.         _StartInfoDrawing
  318. ;
  319. ;
  320. ; --- Handle menu selection from window's menu bar -----------------------------------------
  321. ;
  322.         pea    TaskRec|-16              Pass pointer to Task record for MenuSelect.
  323.         pea    TaskRec
  324.         pei    menuBar+2                Pass handle of menu bar.
  325.         pei    menuBar
  326.         _MenuSelect                     Let user make selection.
  327. ;
  328.         lda    event+TaskData           Get the item's ID number.
  329.         beq    exit                     Was a selection made?
  330. ;
  331.         _EndInfoDrawing                 Switch back to original port.
  332.  
  333. ;
  334. ;         (Handle the menu selection.)
  335. ;
  336. ;    The EndInfoDrawing followed by the StartInfoDrawing call is only
  337. ;    needed when code between them calls the Window Manager.
  338. ;
  339.         pea    tempRect|-16             Pass pointer to RECT to store info bar RECT.
  340.         pea    tempRect
  341.         lda    TaskRec+TaskData+2       Pass pointer of window.
  342.         pha
  343.         lda    TaskRec+TaskData
  344.         pha
  345.         _StartInfoDrawing               Switch to the proper port in the proper state.
  346. ;
  347.         pea    0                        Pass unhilite flag.
  348.         lda    TaskRec+TaskData+2       Pass menu's ID number.
  349.         pha    
  350.         _HiliteMenu                     Unhilite menu's title.
  351. ;
  352. ;
  353. ; --- Clean up and return to polling -------------------------------------------------------
  354. ;
  355. exit    _EndInfoDrawing                 Switch back to original port.
  356. ;
  357.         pea    0                        Make system menu bar current.
  358.         pea    0
  359.         _SetMenuBar
  360. ;
  361.         jmp    poll                     Return to polling user.
  362. ;
  363.  
  364.  
  365. Information Bar Shutdown
  366.  
  367. When the Window Manager closes the window, it is up to you to resolve any 
  368. shutdown necessities associated with the information bar.  Using our window 
  369. menu bar example, the close window might look like the following:
  370.  
  371. ;
  372.         pei    menuBar+2                Pass handle of menu bar
  373.         pei    menuBar
  374.         _SetMenuBar
  375. ;
  376.         pha                             Space for returned menu handle.
  377.         pha
  378.         pea    2                        ID number of second menu.
  379.         _GetMHandle                     Get the menu's handle.
  380.         _DisposeMenu                    Free menu record and associated data.
  381. ;
  382.         pha                             Space for returned menu handle.
  383.         pha
  384.         pea    1                        ID number of first menu.
  385.         _GetMHandle                     Get the menu's handle.
  386.         _DisposeMenu                    Free menu record and associated data.
  387. ;
  388.         pea    0                        Make system menu bar current.
  389.         pea    0
  390.         _SetMenuBar
  391. ;
  392.         pha                             Space for menu bar's handle.
  393.         pha
  394.         pei    <window+2                Pass pointer of window to close.
  395.         pei    <window
  396.         _GetInfoRefCon                  Get the InfoRefCon from the window.
  397.         _DisposeHandle                  Free menu bar record.
  398. ;
  399.         pei    <window+2                Pass pointer of window to close.
  400.         pei    <window
  401.         _CloseWindow                    Now the window can be closed.
  402. ;
  403.  
  404. The type of shutdown you use depends upon the contents of the information bar.
  405.  
  406. Why didn't I put a DisposeMenuBar call in the Menu Manager?  I didn't think of 
  407. it until a week too late.  Sorry.
  408.  
  409.  
  410. Other Information Bar Uses
  411.  
  412. The following suggestions are only theories and have not been tested.
  413.  
  414. o    Display text information, as in Macintosh Finder windows.
  415. o    Split window.  Like the content region, the information bar could be large 
  416.      enough to hold data.
  417. o    Hold controls.  You could scroll data in the content region while keeping 
  418.      the controls which affect the display in place and within the user's]
  419.      reach.  (Note:  The Control Manager currently will not allow controls it
  420.      creates in an information bar.  In this case, NewControl would be using a
  421.      port that is not in your window's port, namely the Window Manager's port.)
  422.  
  423.  
  424. Further Reference
  425. o    Apple IIGS Toolbox Reference, Volumes 1 & 2
  426.  
  427.